#!/usr/bin/env python3
"""
This program calculates all possible yield from crafting
for the given amount of material in minecraft.
"""

__usage__ = """input: <block type> <amount>
output: all possible yield"""

def calculate_yield(cr_table, block, amount):
    """
    This is the function that recursively calculates crafting
    yield
    """
    if (type(cr_table) != type({}) or type(block) != type('') or
            type(amount) != type(int())):
        return False
    for item in cr_table[block]:
        print('{0} {1}'.format((amount // item[2]) * item[1], item[0]), end='')
        if amount % item[2] > 0:
            print(' + {0} {1}'.format(amount % item[2], block))
        else:
            print()
        if item[0] in cr_table:
            calculate_yield(cr_table, item[0], (amount // item[2]) * item[1])

def main():
    """
    Main loop
    """
    cr_table = {'wood':   [('planks', 4, 1), ('charcoal', 1, 1)], \
                'planks': [('sticks', 4, 2), ('button', 1, 1),
                           ('boat', 1, 5), ('slabs', 6, 3)], \
                'sticks': [('torches',4, 1), ('ladder', 3, 7)], \
                'slabs':  []}
    while True:
        try:
            materials = input('input> ')
        except:
            print('\nbye')
            return 0
        try:
            [block, amount] = [str(materials.split()[0]),
                               int(materials.split()[1])]
        except:
            print(__usage__)
            return 1
        calculate_yield(cr_table, block, amount)

if __name__ == '__main__':
    main()
